package cn.com.shopec.erp.product.commo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import cn.com.shopec.erp.common.constant.SZSCMConstant;
import cn.com.shopec.erp.common.page.PageFinder;
import cn.com.shopec.erp.common.utils.LogicUtil;
import cn.com.shopec.erp.product.entity.Defective;
import cn.com.shopec.erp.product.vo.DefectiveVo;

/**
 * 
 * @ClassName: DefectiveConvertor
 * @Description: 次品对象转换器
 * @author: LiangShunWang
 * @date 2016-11-21 下午17:16:22
 * 
 */
@Component
public class DefectiveVoConvertor {

	public List<DefectiveVo> convert2DefectiveVos(List<Defective> defectiveList) {
		List<DefectiveVo> defectiveVos = null;

		if (LogicUtil.isNotNullAndEmpty(defectiveList)) {
			defectiveVos = new ArrayList<DefectiveVo>();

			for (Defective defective : defectiveList) {
				DefectiveVo brandVo = this.convert2DefectiveVo(defective);
				defectiveVos.add(brandVo);
			}
		}

		return defectiveVos;
	}

	public PageFinder<DefectiveVo> convert2PagedDefectiveVos(PageFinder<Defective> pagedBrands) {
		PageFinder<DefectiveVo> pagedBrandVos = null;

		if (LogicUtil.isNotNull(pagedBrands.getData())) {
			List<DefectiveVo> defectiveVos = this.convert2DefectiveVos(pagedBrands.getData());

			pagedBrandVos = new PageFinder<DefectiveVo>(pagedBrands.getPageNo(), pagedBrands.getPageSize(),
					pagedBrands.getRowCount(), defectiveVos);
		}

		return pagedBrandVos;
	}

	public DefectiveVo convert2DefectiveVo(Defective defective) {
		DefectiveVo defectiveVo = null;
		if (LogicUtil.isNotNull(defective)) {
			defectiveVo = new DefectiveVo();
			defectiveVo.setId(defective.getId());
			defectiveVo.setProdNo(defective.getProdNo());
			defectiveVo.setCommoNo(defective.getCommoNo());
			defectiveVo.setCommoName(defective.getCommoName());
			defectiveVo.setDefectiveNumber(defective.getDefectiveNumber());
			defectiveVo.setDefectiveReason(defective.getDefectiveReason());
			defectiveVo.setDealWith(defective.getDealWith());
			defectiveVo.setWhNo(defective.getWhNo());
			defectiveVo.setWhName(defective.getWhName());
			defectiveVo.setStorageMethods(defective.getStorageMethods());
			defectiveVo.setPoNo(defective.getPoNo());
			defectiveVo.setSupCode(defective.getSupCode());
			defectiveVo.setSupName(defective.getSupName());
			defectiveVo.setCreateTime(defective.getCreateTime());
			defectiveVo.setStorageState(defective.getStorageState());
			defectiveVo.setDealwithTime(defective.getDealwithTime());
			defectiveVo.setStorageMan(defective.getStorageMan());
			defectiveVo.setDealwithMan(defective.getDealwithMan());
			defectiveVo.setDeleteFlag(defective.getDeleteFlag());
			defectiveVo.setDescription(defective.getDescription());
			defectiveVo.setProdBarCode(defective.getProdBarCode());
			defectiveVo.setChangedQualifiedQuantity(defective.getChangedQualifiedQuantity());
			defectiveVo.setChangedDefectiveQuantity(defective.getChangedDefectiveQuantity());
			defectiveVo.setAduitTime(defective.getAduitTime());
			defectiveVo.setDeNo(defective.getId());
			defectiveVo.setSpecName(defective.getSpecName());
		}

		return defectiveVo;
	}

	public Defective convert2Defective(DefectiveVo defectiveVo) {
		Defective defective = null;

		if (LogicUtil.isNotNull(defectiveVo)) {
			defective = new Defective();
			defective.setId(defectiveVo.getId());
			defective.setProdNo(defectiveVo.getProdNo());
			defective.setCommoNo(defectiveVo.getCommoNo());
			defective.setCommoName(defectiveVo.getCommoName());
			defective.setDefectiveNumber(defectiveVo.getDefectiveNumber());
			defective.setDefectiveReason(defectiveVo.getDefectiveReason());
			defective.setDealWith(defectiveVo.getDealWith());
			defective.setWhNo(defectiveVo.getWhNo());
			defective.setWhName(defectiveVo.getWhName());
			defective.setStorageMethods(defectiveVo.getStorageMethods());
			defective.setPoNo(defectiveVo.getPoNo());
			defective.setSupCode(defectiveVo.getSupCode());
			defective.setSupName(defectiveVo.getSupName());
			defective.setCreateTime(defectiveVo.getCreateTime());
			defective.setStorageState(defectiveVo.getStorageState());
			defective.setDealwithTime(defectiveVo.getDealwithTime());
			defective.setStorageMan(defectiveVo.getStorageMan());
			defective.setDealwithMan(defectiveVo.getDealwithMan());
			defective.setDeleteFlag(defectiveVo.getDeleteFlag());
			defective.setDescription(defectiveVo.getDescription());
			defective.setChangedQualifiedQuantity(defectiveVo.getChangedQualifiedQuantity());
			defective.setChangedDefectiveQuantity(defectiveVo.getChangedDefectiveQuantity());
			defective.setAduitTime(defectiveVo.getAduitTime());
			defective.setSpecName(defectiveVo.getSpecName());
			if (defectiveVo.getDeleteFlag() == null) {
				defective.setDeleteFlag(SZSCMConstant.DELETE_FLAG_NO);
			} else {
				defective.setDeleteFlag(defectiveVo.getDeleteFlag());
			}
		}

		return defective;
	}

	public Defective convert2Defective(DefectiveVo defectiveVo, Defective defective) {

		if (LogicUtil.isNotNull(defectiveVo) && LogicUtil.isNotNull(defective)) {
			defective.setId(defectiveVo.getId());
			defectiveVo.setProdNo(defective.getProdNo());
			defectiveVo.setCommoNo(defective.getCommoNo());
			defectiveVo.setCommoName(defective.getCommoName());
			defective.setDefectiveNumber(defectiveVo.getDefectiveNumber());
			defective.setDefectiveReason(defectiveVo.getDefectiveReason());
			defective.setDealWith(defectiveVo.getDealWith());
			defective.setWhNo(defectiveVo.getWhNo());
			defective.setWhName(defectiveVo.getWhName());
			defective.setPoNo(defectiveVo.getPoNo());
			defective.setSupCode(defectiveVo.getSupCode());
			defective.setSupName(defectiveVo.getSupName());
			defective.setCreateTime(defectiveVo.getCreateTime());
			defective.setStorageState(defectiveVo.getStorageState());
			defective.setDealwithTime(defectiveVo.getDealwithTime());
			defective.setStorageMan(defectiveVo.getStorageMan());
			defective.setDealwithMan(defectiveVo.getDealwithMan());
			defective.setDeleteFlag(defectiveVo.getDeleteFlag());
			defective.setDescription(defectiveVo.getDescription());
			defective.setProdBarCode(defectiveVo.getProdBarCode());
			return defective;
		} else {
			return null;
		}
	}

}
